<!DOCTYPE html>




<html class="theme-next gemini" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
    
  
  <link href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  
    
      
    

    
  

  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|Lobster Two:300,300italic,400,400italic,700,700italic|Source Code Pro:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="https://cdn.staticfile.org/font-awesome/4.6.2/css/font-awesome.css" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=6.0.0" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="http://tva3.sinaimg.cn/crop.206.47.515.515.180/709d5819jw8f4k1tlmnsij20pr0gytdx.jpg?v=6.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="http://tva3.sinaimg.cn/crop.206.47.515.515.180/709d5819jw8f4k1tlmnsij20pr0gytdx.jpg?v=6.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="http://tva3.sinaimg.cn/crop.206.47.515.515.180/709d5819jw8f4k1tlmnsij20pr0gytdx.jpg?v=6.0.0">


  <link rel="mask-icon" href="http://tva3.sinaimg.cn/crop.206.47.515.515.180/709d5819jw8f4k1tlmnsij20pr0gytdx.jpg?v=6.0.0" color="#222">





  <meta name="keywords" content="vps, java, python, golang, springmvc">




  


  <link rel="alternate" href="/atom.xml" title="张恒的网络日志" type="application/atom+xml">






<meta name="keywords" content="java, python, go, 技术, 学习笔记, spring">
<meta property="og:type" content="website">
<meta property="og:title" content="张恒的网络日志">
<meta property="og:url" content="http://blog.gavinzh.com/404.html">
<meta property="og:site_name" content="张恒的网络日志">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-01-05T08:52:36.912Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="张恒的网络日志">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '6.0.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    fastclick: true,
    lazyload: true,
    tabs: true,
    motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://blog.gavinzh.com/404.html">





  <title>vim-command | 张恒的网络日志</title>
  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-98061925-1', 'auto');
  ga('send', 'pageview');
</script>





</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">张恒的网络日志</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">Zhang Heng's WebSite Blog</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://blog.gavinzh.com/2017/05/04/vim-command/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Gavin Zhang">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars3.githubusercontent.com/u/5567916">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="张恒的网络日志">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">vim-command</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-04T01:25:00+00:00">2017-05-04</time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/笔记/" itemprop="url" rel="index">
                    <span itemprop="name">笔记</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/05/04/vim-command/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count" data-disqus-identifier="2017/05/04/vim-command/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2017/05/04/vim-command/" class="leancloud_visitors" data-flag-title="vim-command">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="/images/pasted-37.png" alt="upload successful"></p>
<a id="more"></a>

<h4 id="插入模式"><a href="#插入模式" class="headerlink" title="插入模式"></a>插入模式</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>i</td>
<td>从光标当前位置开始输入文件</td>
</tr>
<tr>
<td>I</td>
<td>在光标所在行的行首插入</td>
</tr>
<tr>
<td>a</td>
<td>从目前光标所在位置的下一个位置开始输入文字。</td>
</tr>
<tr>
<td>A</td>
<td>在光标所在行的行末插入。</td>
</tr>
<tr>
<td>o</td>
<td>在下面插入一行</td>
</tr>
<tr>
<td>O</td>
<td>在上面插入一行。</td>
</tr>
<tr>
<td>s</td>
<td>删除光标后的一个字符，然后进入插入模式。</td>
</tr>
<tr>
<td>S</td>
<td>删除光标所在的行，然后进入插入模式。</td>
</tr>
</tbody></table>
<h4 id="移动光标"><a href="#移动光标" class="headerlink" title="移动光标"></a>移动光标</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>h</td>
<td>光标左移一格</td>
</tr>
<tr>
<td>j</td>
<td>光标下移一格</td>
</tr>
<tr>
<td>k</td>
<td>光标上移一格</td>
</tr>
<tr>
<td>l</td>
<td>光标右移一格</td>
</tr>
<tr>
<td>w</td>
<td>光标跳到下个字的开头</td>
</tr>
<tr>
<td>e</td>
<td>光标跳到下个字的字尾</td>
</tr>
<tr>
<td>b</td>
<td>光标回到上个字的开头</td>
</tr>
<tr>
<td>nl</td>
<td>光标移动该行的第n个位置，例如：“5l”表示移动到该行的第5个字符</td>
</tr>
<tr>
<td>ctrl+b</td>
<td>屏幕往后移动一页。</td>
</tr>
<tr>
<td>ctrl+f</td>
<td>屏幕往前移动一页。</td>
</tr>
<tr>
<td>ctrl+u</td>
<td>屏幕往后移动半页。</td>
</tr>
<tr>
<td>ctrl+d</td>
<td>屏幕往前移动半页。</td>
</tr>
<tr>
<td>数字“0”</td>
<td>移动到文本的开头。</td>
</tr>
<tr>
<td>G</td>
<td>移动到文件的最后。</td>
</tr>
<tr>
<td>$</td>
<td>移动到光标所在行的行尾。</td>
</tr>
<tr>
<td>“^”</td>
<td>移动到光标所在行的行首。</td>
</tr>
</tbody></table>
<h4 id="删除文字"><a href="#删除文字" class="headerlink" title="删除文字"></a>删除文字</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>x</td>
<td>每按一次，删除光标所在位置的后面一个字符。</td>
</tr>
<tr>
<td>nx</td>
<td>例如：“6x”表示删除光标所在位置后面6个字符。</td>
</tr>
<tr>
<td>X</td>
<td>每按一次，删除光标所在位置的前面一个字符。</td>
</tr>
<tr>
<td>dd</td>
<td>删除光标所在行。</td>
</tr>
<tr>
<td>ndd</td>
<td>从光标所在行开始删除n行。例如：“4dd”表示删除从光标所在行开始的4行字符。</td>
</tr>
</tbody></table>
<h4 id="复制"><a href="#复制" class="headerlink" title="复制"></a>复制</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>yw</td>
<td>将光标所在之处到字尾的字符复制到缓冲区中。</td>
</tr>
<tr>
<td>nyw</td>
<td>复制n个字到缓冲区。</td>
</tr>
<tr>
<td>yy</td>
<td>复制光标所在行到缓冲区。</td>
</tr>
<tr>
<td>nyy</td>
<td>例如：“6yy”表示复制从光标所在行开始6行字符。</td>
</tr>
<tr>
<td>p</td>
<td>将缓冲区内的字符写到光标所在位置。</td>
</tr>
</tbody></table>
<h4 id="更改"><a href="#更改" class="headerlink" title="更改"></a>更改</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
<th>eg</th>
</tr>
</thead>
<tbody><tr>
<td>cw</td>
<td>更改光标所在处的字到字尾处。cnw</td>
<td>例如：“c3w”表示更改3个字。</td>
</tr>
</tbody></table>
<h4 id="跳至指定的行"><a href="#跳至指定的行" class="headerlink" title="跳至指定的行"></a>跳至指定的行</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>ctrl+g</td>
<td>列出光标所在行的行号。</td>
</tr>
<tr>
<td>nG</td>
<td>例如：“15G”，表示移动光标到该文件的第15行行首。</td>
</tr>
</tbody></table>
<h4 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>ZZ</td>
<td>存盘退出</td>
</tr>
<tr>
<td>ZQ</td>
<td>不存盘退出</td>
</tr>
<tr>
<td>r</td>
<td>替换光标所在处的字符。</td>
</tr>
<tr>
<td>R</td>
<td>替换光标所到处的字符，直到按下“ESC”键为止。</td>
</tr>
<tr>
<td>u</td>
<td>撤销上一次操作</td>
</tr>
</tbody></table>
<h4 id="末行模式操作"><a href="#末行模式操作" class="headerlink" title="末行模式操作"></a>末行模式操作</h4><blockquote>
<p>在使用末行模式之前，请记住先按“ESC”键确定已经处于命令行模式后，再按冒号“：”即可进入末行模式。</p>
</blockquote>
<table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>set nu</td>
<td>列出行号</td>
</tr>
<tr>
<td>set nonu</td>
<td>取消列出行号</td>
</tr>
<tr>
<td>set ic</td>
<td>搜索时忽略大小写</td>
</tr>
<tr>
<td>set noic</td>
<td>取消在搜索时忽略大小写。</td>
</tr>
<tr>
<td>n</td>
<td>跳到文件中的某一行,“n”表示一个数字，如输入数字15,再回车就会跳到文本的第15行。</td>
</tr>
<tr>
<td>!cmd</td>
<td>运行shell命令cmd。</td>
</tr>
</tbody></table>
<h4 id="查找字符"><a href="#查找字符" class="headerlink" title="查找字符"></a>查找字符</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>关键字</td>
<td>先按“/”，再输入想查找的字符，如果第一次查找的关键字不是想要的，可以一直按“n”，往后查找一个关键字。</td>
</tr>
<tr>
<td>关键字</td>
<td>先按“?”键，再输入想查找的字符，如果第一次查找的关键字不是想要的，可以一直按“？”，往后查找一个关键字。</td>
</tr>
</tbody></table>
<h4 id="替换字符"><a href="#替换字符" class="headerlink" title="替换字符"></a>替换字符</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>s /SPARCH/REPLACE/g</td>
<td>把当前光标所处的行中的SEARCH单词替换成REPLACE，并把所有SEARCH高亮显示。</td>
</tr>
<tr>
<td>%s /SPARCH/REPLACE</td>
<td>把文档中所有SEARCH替换成REPLACE。</td>
</tr>
<tr>
<td>n1,n2 s /SPARCH/REPLACE/g</td>
<td>n1、n2表示数字，表示从n1行到n2行，把SEARCH替换成REPLACE。</td>
</tr>
</tbody></table>
<h4 id="命令行模式：移动光标的方法"><a href="#命令行模式：移动光标的方法" class="headerlink" title="命令行模式：移动光标的方法"></a>命令行模式：移动光标的方法</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>h或向左方向键（←）</td>
<td>光标向左移动一个字符</td>
</tr>
<tr>
<td>j或向下方向键（↓）</td>
<td>光标向下移动一个字符</td>
</tr>
<tr>
<td>k或向上方向键（↑）</td>
<td>光标向上移动一个字符</td>
</tr>
<tr>
<td>l或向右方向键（→）</td>
<td>光标向右移动一个字符</td>
</tr>
<tr>
<td>移动多行</td>
<td>如果想要进行多次移动的话，例如；向下移动30行，可以使用“30j”或“30↓”的组合键，即</td>
</tr>
<tr>
<td>[Ctrl]+[f]</td>
<td>屏幕“向下”移动一页，相当于[Page Down]按键</td>
</tr>
<tr>
<td>[Ctrl]+[b]</td>
<td>屏幕“向上”移动一页，相当于[Page Up]按键</td>
</tr>
<tr>
<td>[Ctrl]+[d]</td>
<td>屏幕“向下”移动半页</td>
</tr>
<tr>
<td>[Ctrl]+[u]</td>
<td>屏幕“向上”移动半页</td>
</tr>
</tbody></table>
<h4 id="命令行模式：移动光标的方法-1"><a href="#命令行模式：移动光标的方法-1" class="headerlink" title="命令行模式：移动光标的方法"></a>命令行模式：移动光标的方法</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>&#124;</td>
<td>光标移动到非空格符的下一行</td>
</tr>
<tr>
<td>光标移动到非空格符的上一行n<code>&lt;space&gt;</code></td>
<td>n表示“数字”，例如20.按下数字后再按空格键，光标会向右移动这一行n个字符。例如20<code>&lt;space&gt;</code>则光标会向后面移动20个字符距离</td>
</tr>
<tr>
<td>0</td>
<td>这是数字“0”：移动到这一行的最前面字符处（常用）</td>
</tr>
<tr>
<td>$</td>
<td>移动到这一行的最后面字符处（常用）</td>
</tr>
<tr>
<td>H</td>
<td>光标移动到这个屏幕的最上方哪一行</td>
</tr>
<tr>
<td>M</td>
<td>光标移动到这个屏幕的中央哪一行</td>
</tr>
<tr>
<td>L</td>
<td>光标移动到这个屏幕的最下方哪一行</td>
</tr>
<tr>
<td>G</td>
<td>移动到这个文件的最后一行（常用）</td>
</tr>
<tr>
<td>nG</td>
<td>n为数字。移动到这个文件的第n行。例如20G则会移动到这个文件的第20行（可配合：set nu）</td>
</tr>
<tr>
<td>gg</td>
<td>移动到这个文件的第一行，相当于1G（常用）</td>
</tr>
<tr>
<td>n<code>&lt;Enter&gt;</code></td>
<td>n为数字。光标向下移动n行（常用）</td>
</tr>
</tbody></table>
<h4 id="命令行模式：搜索与替换"><a href="#命令行模式：搜索与替换" class="headerlink" title="命令行模式：搜索与替换"></a>命令行模式：搜索与替换</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>/word</td>
<td>从光标位置开始，向下寻找一个名为word的字符串。例如要在文件内搜索vbird这个字符串，就输入/vbird即可（常用）</td>
</tr>
<tr>
<td>?word</td>
<td>从光标位置开始，向上寻找一个名为word的字符串</td>
</tr>
<tr>
<td>n</td>
<td>n是英文按键。表示“重复前一个搜索的动作”。举例来说，如果刚刚执行/vbird去向下搜索vbird字符串，则按下n后，会向下继续搜索下一个名称为vbird的字符串。如果是执行?vbird的话，那么按下n，则会向上继续搜索名称为vbird的字符串</td>
</tr>
<tr>
<td>N</td>
<td>这个N是英文按键。与n刚好相反，为“反向”进行前一个搜索操作。例如/vbird后，按下N则表示“向上”搜索vbird</td>
</tr>
</tbody></table>
<h4 id="命令行模式：搜索与替换-1"><a href="#命令行模式：搜索与替换-1" class="headerlink" title="命令行模式：搜索与替换"></a>命令行模式：搜索与替换</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>:n1、n2s/word1/word2/g</td>
<td>n1与n2为数字。在第n1与n2行之间寻找word1这个字符串，并将该字符串替换为word2。举例来说，在100到200行之间搜索vbird并替换为VBIRD则：“:100、200s/vbird/VBIRD/g”（常用）</td>
</tr>
<tr>
<td>:1、$s/word1/word2/g</td>
<td>从第一行到最后一行寻找word1字符串，并将该字符串替换为word2（常用）</td>
</tr>
<tr>
<td>:1、$s/word1/word2/gc</td>
<td>从第一行到最后一行寻找word1字符串，并将该字符串替换为word2。且在替换前显示提示符给用户确认（conform）是否需要替换（常用）命令行模式：删除、复制与粘贴</td>
</tr>
<tr>
<td>p,P</td>
<td>p为将已复制的数据粘贴到光标的下一行，P则为贴在光标上一行。举例来说，当前光标在第20行，且已经复制了10行数据。则按下p后，那10行数据会粘在原来的20行之后，即由21行开始贴。但如果是按下P，那么原来的第20行会被变成30行（常用）</td>
</tr>
<tr>
<td>J</td>
<td>将光标所在行与下一列的数据结合成同一行</td>
</tr>
<tr>
<td>c</td>
<td>重复删除多个数据，例如向下删除10行，[10cj]</td>
</tr>
<tr>
<td>u</td>
<td>复原前一个操作（常用）</td>
</tr>
<tr>
<td>[Ctrl]+r</td>
<td>重做上一个操作（常用）U与[Ctrl]+r是很常用的命令。一个是复原，另一个则是重做一次。利用这两个功能按键，编辑起来就得心应手。</td>
</tr>
</tbody></table>
<h4 id="命令行模式：删除、复制与粘贴"><a href="#命令行模式：删除、复制与粘贴" class="headerlink" title="命令行模式：删除、复制与粘贴"></a>命令行模式：删除、复制与粘贴</h4><blockquote>
<p>这就是小数点。意思是重复前一个动作。如果想重复删除、重复粘贴，按下小数点“.”就可以（常用）;<br>插入模式</p>
</blockquote>
<table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>i、I</td>
<td>插入：在当前光标所在处插入输入文字，已存在的文字会向后退；其中，i为“从当前光标所在处插入”，I为“在当前所在行的第一个非空格符处开始插入”（常用）</td>
</tr>
<tr>
<td>a、A</td>
<td>a为“从当前光标所在的下一个字符处开始插入”，A为“从光标所在行的最后一个字符处开始插入”（常用）</td>
</tr>
<tr>
<td>o、O</td>
<td>这是英文字母o的大小写。o为“在当前光标所在的下一行处插入新的一行”，O为“在当前光标所在处的上一行插入新的一行”（常用）</td>
</tr>
<tr>
<td>r、R</td>
<td>替换：r会替换光标所在的那一个字符；R会一直替换光标所在的文字，直到按下Esc键为止（常用）</td>
</tr>
</tbody></table>
<blockquote>
<p>使用上面这些按键时，在vi画面的左下角处会出现“—INSERT–”或“—REPLACE–”的字样。通过名称就知道是什么操作。特别注意，上面也提过了，想在文件中输入字符时，一定要在左下角处看到INSERT/ REPLACE才能输入。Esc 退出插入模式，回到命令行模式中（常用）</p>
</blockquote>
<h4 id="末行命令模式"><a href="#末行命令模式" class="headerlink" title="末行命令模式"></a>末行命令模式</h4><table>
<thead>
<tr>
<th>key</th>
<th>desc</th>
</tr>
</thead>
<tbody><tr>
<td>:w</td>
<td>将编辑的数据写入硬盘文件中（常用）</td>
</tr>
<tr>
<td>:w!</td>
<td>若文件属性为“只读”时，强制写入该文件。不过，到底能不能写入，与文件权限有关</td>
</tr>
<tr>
<td>:q</td>
<td>离开vi（常用）</td>
</tr>
<tr>
<td>:q!</td>
<td>若曾修改过文件，又不想存储，使用！为强制离开不存储文件注意一下，那个感叹号（!）在vi当中，常常具有“强制”的意思。</td>
</tr>
<tr>
<td>:wq</td>
<td>存储后离开，若为:wq!则为强制存储后离开（常用）</td>
</tr>
<tr>
<td>:e!</td>
<td>将文件还原到最原始的状态</td>
</tr>
<tr>
<td>ZZ</td>
<td>若文件没有更改，则不存储离开，若文件已经更改，则存储后离开</td>
</tr>
<tr>
<td>:w[filename]</td>
<td>将编辑的数据存储成另一个文件（类似另存新文件）</td>
</tr>
<tr>
<td>:r[filename]</td>
<td>在编辑的数据中，读入另一个文件的数据。即将“filename”这个文件内容加到光标所在行的后面</td>
</tr>
<tr>
<td>:n1、n2 w[filename]</td>
<td>将n1到n2的内容存储成filename文件</td>
</tr>
<tr>
<td>:!command</td>
<td>暂时离开vi到命令模式下执行command的显示结果。例如，“:! ls /home”，即可在vi中查看/home中以ls输出的文件信息</td>
</tr>
<tr>
<td>:set nu</td>
<td>显示行号，设置之后，会在每一行的前缀显示该行的行号</td>
</tr>
<tr>
<td>:set nonu</td>
<td>与set nu相反，为取消行号</td>
</tr>
</tbody></table>
<blockquote>
<p>特别注意，在vi中，“数字”是很有意义的。数字通常表示重复做几次的意思。也有可能表示要去哪里的意思。举例来说，要删除50行，则是用“50dd”。数字加在动作之前。要向下移动20行，使用“20j”或“20↓”即可。</p>
</blockquote>
<p>整理自<a rel="noopener" href="http://www.cnblogs.com/jeakon/archive/2012/08/13/2816802.html" target="_blank">vim命令大全</a></p>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    Gavin Zhang
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://blog.gavinzh.com/2017/05/04/vim-command/" title="vim-command">http://blog.gavinzh.com/2017/05/04/vim-command/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux/" rel="tag"># Linux</a>
          
            <a href="/tags/vim/" rel="tag"># vim</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/05/03/javascript-stringformatter-tutorial/" rel="next" title="StringFormatter，一个javascript编写的字符串格式化库">
                <i class="fa fa-chevron-left"></i> StringFormatter，一个javascript编写的字符串格式化库
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/05/14/freemarker-number-formatter/" rel="prev" title="freemarker-number-formatter">
                freemarker-number-formatter <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://avatars3.githubusercontent.com/u/5567916" alt="Gavin Zhang">
            
              <p class="site-author-name" itemprop="name">Gavin Zhang</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">129</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">158</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/jiangmitiao" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:me at gavinzh.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#插入模式"><span class="nav-number">1.</span> <span class="nav-text">插入模式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#移动光标"><span class="nav-number">2.</span> <span class="nav-text">移动光标</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#删除文字"><span class="nav-number">3.</span> <span class="nav-text">删除文字</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#复制"><span class="nav-number">4.</span> <span class="nav-text">复制</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#更改"><span class="nav-number">5.</span> <span class="nav-text">更改</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#跳至指定的行"><span class="nav-number">6.</span> <span class="nav-text">跳至指定的行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#其他"><span class="nav-number">7.</span> <span class="nav-text">其他</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#末行模式操作"><span class="nav-number">8.</span> <span class="nav-text">末行模式操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查找字符"><span class="nav-number">9.</span> <span class="nav-text">查找字符</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#替换字符"><span class="nav-number">10.</span> <span class="nav-text">替换字符</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#命令行模式：移动光标的方法"><span class="nav-number">11.</span> <span class="nav-text">命令行模式：移动光标的方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#命令行模式：移动光标的方法-1"><span class="nav-number">12.</span> <span class="nav-text">命令行模式：移动光标的方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#命令行模式：搜索与替换"><span class="nav-number">13.</span> <span class="nav-text">命令行模式：搜索与替换</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#命令行模式：搜索与替换-1"><span class="nav-number">14.</span> <span class="nav-text">命令行模式：搜索与替换</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#命令行模式：删除、复制与粘贴"><span class="nav-number">15.</span> <span class="nav-text">命令行模式：删除、复制与粘贴</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#末行命令模式"><span class="nav-number">16.</span> <span class="nav-text">末行命令模式</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2013 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Gavin Zhang</span>

  

  
</div>





<div>
	<a href="http://www.beian.miit.gov.cn/" target="_blank">陕ICP备17010002号-1</a>
</div>





        




  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=61868582";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1261805793&web_id=1261805793" language="JavaScript"></script>
  </div>



        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>





  



  






  













  
  
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.staticfile.org/fastclick/1.0.6/fastclick.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.staticfile.org/velocity/2.0.5/velocity.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.staticfile.org/velocity/2.0.5/velocity.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.0.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.0.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.0"></script>



  


  

    
      <script id="dsq-count-scr" src="https://zhang-hengs-website-blog.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://blog.gavinzh.com/2017/05/04/vim-command/';
          this.page.identifier = '2017/05/04/vim-command/';
          this.page.title = 'vim-command';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://zhang-hengs-website-blog.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("EhAMmIXTRGtethTcgYwA9afH-gzGzoHsz", "jzP1TaBhMleAUgPLXyB0h8oQ");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  
  


  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=6.0.0"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=6.0.0"></script>


  

</body>
</html>
